<?php

namespace App\Repositories\Cart;

use Illuminate\Support\Facades\DB;
use Prettus\Repository\Eloquent\BaseRepository;
use Prettus\Repository\Criteria\RequestCriteria;
use App\Repositories\Cart\favourable_activityRepository;
use App\Models\FavourableActivity;

/**
 * Class FavourableActivityRepositoryEloquent.
 *
 * @package namespace App\Repositories;
 */
class FavourableActivityRepositoryEloquent extends BaseRepository implements FavourableActivityRepository
{
    /**
     * Specify Model class name
     *
     * @return string
     */
    public function model()
    {
        return FavourableActivity::class;
    }

    /**
     * 获取商品可参与的活动
     */
    public function getGoodsActivity($goods,$userRank){
         return DB::table('favourable_activity')->whereRaw('FIND_IN_SET('.$userRank.',user_rank) and start_time<'.gm_time().' and end_time>'.gm_time().' and (act_range=0 or act_range=1 and FIND_IN_SET('.$goods['cat_id'].',act_range_ext) or act_range=2 and FIND_IN_SET('.$goods['brand_id'].',act_range_ext) or act_range=3 and FIND_IN_SET('.$goods['goods_id'].',act_range_ext))')
        ->get();
    }

    

    /**
     * Boot up the repository, pushing criteria
     */
    public function boot()
    {
        $this->pushCriteria(app(RequestCriteria::class));
    }
    
}
